<jsp:include page="../Apariencia/Cabecera.jsp"/>

<%@page contentType="text/html" pageEncoding="UTF-8" import="Funcionalidad.*, java.util.*,java.net.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%

        if (session.getAttribute("loginuser") != null) {
            int rol = (Integer) session.getAttribute("loginrol");
            if (rol == 1) {

                int id_post = Integer.parseInt(request.getParameter("id"));

                List<Post> post = new ArrayList();
                try {
                    post = Posts.consultaPost(id_post);
                } catch (Exception ex) {
                    out.print(ex.getMessage());
                }%>
<html>
    <head>
        <title>FLOG - Administraci&oacute;n Post</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <div id="administracion" class="admonBorraPost">
        <body>
            <h1>¿Realmente desea borrar la entrada?</h1>
            <form action="" method="POST">
                <table border="0">
                    <%
                    URLDecoder deco = new URLDecoder();
                Iterator it = post.iterator();
                String texto = "", titulo = "";
                while (it.hasNext()) {
                    Post pos = (Post) it.next();
                    titulo = deco.decode(pos.getTitulo(), "ISO-8859-1");
                    texto = deco.decode(pos.getTexto(), "ISO-8859-1");
                    %>
                    <tr>
                        <th>Titulo</th>
                    </tr>
                    <tr>
                        <td>
                            <input type="text" name="titulo" value="<%=titulo%>" size="107" readonly="readonly" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <textarea name="texto" rows="30" cols="80" readonly="readonly"><%=texto%></textarea>
                        </td>
                    </tr>
                </table>
                <table border="0">
                    <tr>
                        <td>
                            <input type="submit" value="Borrar" name="borrar" />
                        </td>
                    
                
                <%
                }
                %>
            </form>
            <%
                if (request.getParameter("borrar") != null) {
                    try {
                    Posts.deletePost(id_post);
            %>
            <h3> Post Eliminado∫ con exito</h3>
            <jsp:forward page="../Administracion/AdmonPost.jsp"/>
            <%
                    } catch (Exception e) {
                    }
                }


            %>
            <form action= "AdmonPost.jsp" method="POST">
                <td>
                <input type="submit" value="volver" name="Volver" />
                </td>
                </tr>
                </table>
            </form>
        </body>
    </div>
</html>
<%
            } else {
                response.sendRedirect("../Apariencia/VistaPost.jsp");
            }
        }
%>
